package cn.sinata.wanglin.property.activity;

import android.text.Html;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.google.gson.JsonObject;
import com.xilada.xldutils.activitys.TitleActivity;
import com.xilada.xldutils.view.TwoTextLinearView;

import butterknife.BindView;
import cn.sinata.wanglin.R;
import cn.sinata.wanglin.net.HttpManager;
import cn.sinata.wanglin.net.model.util.JsonUtils;
import cn.sinata.wanglin.net.model.util.ResultDataSubscriber;
import cn.sinata.wanglin.utils.ImageUtil;

public class PropertyCompanyActivity extends TitleActivity {

    @BindView(R.id.imageView)
    SimpleDraweeView imageView;
    @BindView(R.id.ttlv_name)
    TwoTextLinearView ttlv_name;
    @BindView(R.id.ttlv_time)
    TwoTextLinearView ttlv_time;
    @BindView(R.id.ttlv_phone)
    TwoTextLinearView ttlv_phone;
    @BindView(R.id.ttlv_address)
    TwoTextLinearView ttlv_address;
//    @BindView(R.id.mWebView)
//    WebView mWebView;
    @BindView(R.id.tv_content)
    TextView tv_content;
    private String id;

    @Override
    protected int setContentId() {
        return R.layout.activity_property_company;
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("物业介绍");

        id = getIntent().getStringExtra("id");
        showDialog();
        getData();
    }

    void getData() {
        HttpManager.getCompanyInfo(id)
                .subscribe(new ResultDataSubscriber<JsonObject>(this) {
                    @Override
                    public void onSuccess(String msg, JsonObject jsonObject) {
                        JsonUtils jsonUtils = new JsonUtils(jsonObject);
                        String bgImg = jsonUtils.optString("bgImg");
                        imageView.setImageURI(ImageUtil.parseImageUri(bgImg));
                        ttlv_name.setRightText(jsonUtils.optString("propertyName"));
                        ttlv_time.setRightText(jsonUtils.optString("workTime"));
                        ttlv_phone.setRightText(jsonUtils.optString("contactNumber"));
                        ttlv_address.setRightText(jsonUtils.optString("address"));
                        tv_content.setText(Html.fromHtml(jsonUtils.optString("companyInfo")));
                    }
                });
    }
}
